export const timeSet = () => {
  function getDateTime(givenTime: string): string {
    const date = new Date(givenTime);
    const year = date.getFullYear();
    const month = (date.getMonth() + 1).toString().padStart(2, "0");
    const day = date.getDate().toString().padStart(2, "0");
    const hours = date.getHours().toString().padStart(2, "0");
    const minutes = date.getMinutes().toString().padStart(2, "0");

    return `${year}-${month}-${day} ${hours}:${minutes}`;
  }
  function getDays(givenTime: string): string {
    const givenDate = new Date(givenTime);
    const currentDate = new Date();
    const timeDifference = currentDate.getTime() - givenDate.getTime();
    const days = Math.floor(timeDifference / (1000 * 60 * 60 * 24));
    if (days > 0) {
      return `${days} 天前`;
    }
    const hours = Math.floor(timeDifference / (1000 * 60 * 60));
    if (hours > 0) {
      return `${hours} 小时前`;
    }
    const minutes = Math.floor(timeDifference / (1000 * 60));
    return `${minutes} 分钟前`;
  }
  function getMinutes(time: number): string {
    const hours = Math.floor(time / (60 * 60));
    if (hours > 0) {
      return `${hours} 小时`;
    }
    const minutes = Math.floor(time / 60);
    return `${minutes} 分钟`;
  }
  function getTime(seconds: number): any {
    const hours = Math.floor(seconds / 3600);
    const minutes = Math.floor((seconds % 3600) / 60);
    const seconds_ = seconds % 60;
    return {
      hours: hours.toString().padStart(2, "0"),
      minutes: minutes.toString().padStart(2, "0"),
      second: seconds_.toString().padStart(2, "0"),
    };
  }
  return {
    getTime,
    getDays,
    getMinutes,
    getDateTime,
  };
};
